﻿Public Class frmConsultaraspirante

    Private Sub frmConsultaraspirante_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    End Sub

    Private Sub frmConsultaraspirante_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cmbConsultapor.Items.Insert(0, "Numero de proceso")
        Me.cmbConsultapor.Items.Insert(1, "Numero identificación")
        Me.cmbConsultapor.SelectedIndex = 0


        mdlHerramientas.loadOption()
        mdlConexion.blnOnDB = True

        Dim dstRecord As New DataSet
        dstRecord.Tables.Add("Tipoidentificacion")
        mdlCRUD.loadRecord(dstRecord, "Tipoidentificacion", "tipoidentificacion", "", Nothing)

        Me.cmbTipoidentificacion.DataSource = dstRecord.Tables("Tipoidentificacion")
        Me.cmbTipoidentificacion.DisplayMember = dstRecord.Tables("Tipoidentificacion").Columns(1).Caption.ToString
        Me.cmbTipoidentificacion.ValueMember = dstRecord.Tables("Tipoidentificacion").Columns(0).Caption.ToString
        Me.cmbTipoidentificacion.Enabled = False

        mdlConexion.blnOnDB = False
    End Sub

    Private Sub cmbConsultapor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbConsultapor.SelectedIndexChanged
        If Me.cmbConsultapor.SelectedIndex = 1 Then
            Me.cmbTipoidentificacion.Enabled = True
        Else
            Me.cmbTipoidentificacion.Enabled = False
        End If
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub btnContinuar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinuar.Click
        If Trim(Me.txtNumero.Text) = "" Then
            MsgBox("Debe digitar el " & Me.cmbConsultapor.SelectedItem.ToString, MsgBoxStyle.Exclamation, "Consultar Aspirante")
        Else
            Select Case Me.cmbConsultapor.SelectedIndex
                Case 0
                    mdlIntegracion.lngIdProceso = Me.txtNumero.Text
                Case 1
                    mdlIntegracion.getIdProceso(Me.cmbTipoidentificacion.SelectedValue.ToString, Me.txtNumero.Text)
            End Select

            If mdlIntegracion.lngIdProceso <> 0 Then
                Dim dstRecord As New DataSet
                Dim strCondicion As String = "aspirante_numeroproceso = '" & mdlIntegracion.lngIdProceso & "'"

                dstRecord.Tables.Add("Datoaspirante")
                mdlCRUD.loadRecord(dstRecord, "Datoaspirante", "aspirante", strCondicion, Nothing)

                Dim intNumrows As Integer = dstRecord.Tables("Datoaspirante").Rows.Count.ToString

                If intNumrows > 0 Then
                    Dim arrRow As Array
                    arrRow = dstRecord.Tables("Datoaspirante").Rows(0).ItemArray.ToArray

                    mdlIntegracion.intIdaspirante = arrRow(1).ToString
                Else
                    mdlIntegracion.getDatosaspirante()
                End If
            Else
                MsgBox("El " & Me.cmbConsultapor.SelectedItem.ToString & " " & Me.txtNumero.Text & " no se encuentra registardo", MsgBoxStyle.Information, "Consultar Aspirante")
            End If
        End If

        If mdlIntegracion.lngIdProceso <> 0 And mdlIntegracion.intIdaspirante <> 0 Then
            Dim frmAspirante As New frmRegistroaspirante
            MsgBox("Numero de proceso: " & mdlIntegracion.lngIdProceso & Chr(13) & "Id Aspirante: " & mdlIntegracion.intIdaspirante, MsgBoxStyle.Information, "Proceso")

            frmAspirante.MdiParent = mdiPrincipal
            frmAspirante.Show()
        End If
    End Sub
End Class